<?php
  include("../conn.php");
  include("../app.php");
  $code = $_POST['code'];
  $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$sessionKey}&js_code={$code}&grant_type=authorization_code";
  $resp = file_get_contents($url);
  $robot = json_decode($resp);
  $openid = $robot -> openid;

  $sql = "SELECT * FROM `user` where `openid`='$openid'";
  $query = mysql_query($sql);
  while ($rs = mysql_fetch_array($query)) $user = array(
    'id' => $rs['id'],
    'name' => $rs['name'],
    'nick' => $rs['nick'],
    'gender' => $rs['gender'],
    'phone' => $rs['phone'],
    'contact' => $rs['contact'],
    'validity' => $rs['validity'],
    'last_login' => $rs['last_login'],
    'date' => $rs['date'],
    'city' => $rs['city'],
    'language' => $rs['language'],
    'introduction' => $rs['introduction'],
    'avatar' => $rs['avatar'],
  );
  print_r(json_encode($user));
?>